Skip to content

fix(indexer): correct inverted gitignore polarity in ShouldIndexFile - #113

Merged
oc-engteam merged 1 commit into
mainfrom
fix/shouldindexfile-gitignore-polarity
Jul 10, 2026
Merged

fix(indexer): correct inverted gitignore polarity in ShouldIndexFile#113
oc-engteam merged 1 commit into
mainfrom
fix/shouldindexfile-gitignore-polarity

Conversation

@oc-engteam

Copy link
Copy Markdown
Collaborator

What & why

ShouldIndexFile (the incremental single-file update path, reached from
POST /api/v1/document/updatehandleUpdateDocument) inverted the gitignore filter for
workspaces configured with Exclude.UseGitIgnore=true.

The three path filters have different polarity:

constructor Match(p)==true means contract
GitIgnoreFilter (= !ignore.IsIgnored) not ignored → keep keep-filter
utils.NewSimpleFilter(patterns) matches a pattern → exclude exclude-filter
utils.NewSimpleFilterExclude(patterns) doesn't match → keep keep-filter

ShouldIndexFile built the gitignore branch with a keep-filter but consumed it with
NewSimpleFilter's exclude-convention (if exclude.Match(relPath,false) { return false }).
Result for UseGitIgnore=true workspaces on the incremental path:

  • a not-ignored source file (Match=true) → return falseskipped (never re-indexed)
  • a gitignored file (Match=false) → falls through → indexed (junk like build/, vendor/)

The full-scan path (processWorkspace) already used NewSimpleFilterExclude (keep-filter) + ListFiles
(keep where Match==true) and was correct — so only the incremental path was inverted. Default is
use_git_ignore: false, so only opt-in workspaces were affected.

Fix

Introduce one helper, buildExcludeFilter, as the single source of truth for the exclude
keep-filter, and route both call sites through it so the two can never drift to opposite polarity
again:

// buildExcludeFilter returns a keep-filter: Match==true => keep, Match==false => exclude.
func buildExcludeFilter(baseDir string, exclude types.Exclude) fsutils.ListFileFilter {
    if exclude.UseGitIgnore {
        return &GitIgnoreFilter{ignore: gitutils.NewGitIgnore(baseDir, true)}
    }
    return utils.NewSimpleFilterExclude(exclude.Customized)
}
  • ShouldIndexFile now skips when the keep-filter returns false: if !exclude.Match(relPath, false) { return false }.
  • processWorkspace routed through the same helper — behavior unchanged (its two arms are the
    filter it already constructed inline).

No on-disk format / API / reindex impact.

Tests

Rewrote the previously assertion-free TestShouldIndexFile_WithGitIgnoreFilter
(_ = ShouldIndexFile(...) — which is why the inversion slipped through) into an assertive test:

  • main.go (not ignored) → indexed
  • app.log (ignored by *.log) → skipped
  • build/out.go (under ignored build/) → skipped

All three fail on the pre-fix code (verified red) and pass after. The customized-exclude branch stays
covered by the existing TestShouldIndexFile_WithCustomExcludeFilters, so both buildExcludeFilter
branches reach 100% coverage.

Verification

  • Gates: gofmt/go build/go vet/go test/go test -race all green; buildExcludeFilter 100%,
    ShouldIndexFile 100% coverage.

  • End-to-end with the real server binary (use_git_ignore: true, incremental /document/update):

    file before after
    keep2.go (not ignored) File Ignored ❌ / unsearchable Ok ✓ / searchable
    ignored2.go (gitignored) Ok ❌ / searchable File Ignored ✓ / absent

🤖 Generated with Claude Code
via Happy

…via a shared exclude-filter helper

ShouldIndexFile paired GitIgnoreFilter (a keep-filter: Match==true means "not
ignored, keep") with NewSimpleFilter's exclude-consumption (if Match { return
false }), so for UseGitIgnore=true workspaces the incremental single-file update
path was inverted: not-ignored source files were skipped and gitignored files
were indexed. The full-scan path (processWorkspace) was already correct.

Introduce buildExcludeFilter as the single source of truth for the exclude
keep-filter and route both ShouldIndexFile and processWorkspace through it;
ShouldIndexFile now skips when the keep-filter returns false. Rewrite the
previously assertion-free gitignore test into an assertive one covering the
kept/ignored/ignored-dir cases.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@oc-engteam
oc-engteam merged commit 35aacaf into main Jul 10, 2026
4 checks passed
@oc-engteam
oc-engteam deleted the fix/shouldindexfile-gitignore-polarity branch July 10, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants